<script>
    //调用微信JS api 支付
    var _model = '{$model}';
    function jsApiCall() {
        WeixinJSBridge.invoke('getBrandWCPayRequest', {$jsApiParameters}, function (res) {
            WeixinJSBridge.log(res.err_msg);
            if (res.err_msg == 'get_brand_wcpay_request:ok') {
                if (_model == 'activity') {
                    window.location.href = '{:url("activity/index")}';
                } else if (_model == 'order') {
                    window.location.href = '{:url("order/index")}';
                } else if (_model == 'order_zb') {
                    get_commemt_list('prepend');
                }
            } else {
                if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                    $.toptip('支付已取消', 'error');
                    setTimeout(function () {
                        if (_model == 'activity') {
                            window.location.href = '{:url("activity/index")}';
                        } else if (_model == 'order') {
                            window.location.href = '{:url("order/index")}';
                        }
                    }, 888);
                } else {
                    console.log(res);
                    $.toptip(res.err_msg, 'error');
                }
                $('#loadingToast').hide();
            }
        });
    }

    function callpay() {
        if (typeof(WeixinJSBridge) == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }
</script>
